#include <iostream>
#include <string>

using namespace std;

bool IsPime(int n)
{
    for (int i = 2; i < n; i++)
    {
        if (n % i == 0) return false;
    }
    return true;
}

int nearstPime(int n) {
    int offset = 0;
    while (true) {
        if (IsPime(n - offset)) return n - offset;
        if (IsPime(n + offset)) return n + offset;
        offset++;
    }
}

int main()
{
    int wordsCount = 0;
    string line, word = "";
    getline(cin, line);
    line += ' ';
    string chisla = "";

    for (char ch : line)
    {
        if (ch == ' ') {
            wordsCount++;
            if (word == "zero") {
                chisla += "0";
            }
            if (word == "one") {
                chisla += "1";
            }
            if (word == "two") {
                chisla += "2";
            }
            if (word == "three") {
                chisla += "3";
            }
            if (word == "four") {
                chisla += "4";
            }
            if (word == "five") {
                chisla += "5";
            }
            if (word == "six") {
                chisla += "6";
            }
            if (word == "seven") {
                chisla += "7";
            }
            if (word == "eight") {
                chisla += "8";
            }
            if (word == "nine") {
                chisla += "9";
            }
        
            
            word.clear();
        }
        else
        {
            word += ch;
        } 
        

    }
    
    if (size(chisla) != 3) {
        cout << "Wrong input";
    }
    else
    {
        int f = stoi(chisla);
        cout << nearstPime(f);
    }
}


